﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common.Util;

namespace WindowsTools.SqlOption.BOOption
{
    public partial class FromBODef : Form
    {
        public FromBODef()
        {
            InitializeComponent();
        }


        public string GetBoStr()
        {
            StringBuilder stringBuilder = new StringBuilder();
//            stringBuilder.Append(@"记录标识:EntryID
//	                                记录状态:EntryState
//	                                业务对象标识:BOID
//	                                业务对象版本:BOVersion
//	                                业务对象状态:BOState
//	                                业务对象状态:BOSubState	
//	                                项目编号:ProjectNo
//	                                项目名称:ProjectName
//	                                项目类型:ProjectType 
//	                                项目单位ID:	 	ProjectOrgID
//	                                项目单位Name:	 	ProjectOrgName
//	                                项目启动年度:ProjectYear
//	                                项目预算:VA
//	                                项目合同金额:VAContract
//	                                项目已支付金额:VPaid
//	                                项目已支付合同:VPaidContract
//	                                项目已支付费用:VPaidFee
//	                                项目本年已支付金额:VPaidBN
//	                                项目本年已支付合同:VPaidContractBN
//	                                项目本年已支付费用:VPaidFeeBN
//	                                周月报类型:ReportType
//	                                项目模板:TemplateID
//	                                项目模板:TemplateName	
//	                                项目供应商:Supplier
//	                                项目实施单位:BuilderOrgID
//	                                项目实施单位:BuilderOrgName 
//	                                项目目标:ProjectTarget
//	                                项目范围:ProjectScope
//	                                业务需求:BizRequirement
//	                                方案简述:ProposalDesc
//	                                ROI分析:ROI
//	                                项目计划请示日期:PRequestDate
//	                                项目计划启动日期:PStartDate	
//	                                备注:Remark
//	                                活动标记:ActiveFlag 
//	                                修订者:	ModifiedBy
//	                                修订时间:ModifiedAt
//	                                修订原因:ModifiedReason
//	                                创建者:	CreatedBy
//	                                创建时间:CreatedAt
//	                                删除者:	DeletedBy
//	                                删除时间:DeletedAt
//	                                删除原因:DeletedMemo");

            stringBuilder.Append(@"记录标识:EntryID
                                    是否新建项目:NewProjectFlag
                                    替代旧系统名称:OldProjectName
                                    是否信息化领导小组审核:	JTApproveFlag
                                    项目监控类型:MonitorType
                                    是否单独立项:IndependentFlag
                                    是否一是一批:SingleFlag
                                    是否方案评审:ProposalEvlFlag
                                    是否财务评审:FinanceEvlFlag
                                    是否财务备案:FinanceBackupFlag
                                    其他管理要求:MgrNeed
                                    单独立项流程状态:StartWFState
                                    项目验收流程状态:FinishWFState");

            return stringBuilder.ToString();

        }

        private void CreateDef_Click(object sender, EventArgs e)
        {
            StringBuilder showSql = new StringBuilder();

            string boStr = GetBoStr();
            var boarr = boStr.Replace("\r\n\t", "%").Split('%');

            foreach (string str in boarr)
            {
                showSql.Append(GetSqlRow("BODef", GetArrDy(str)));
            }

            FormSQLShow fromSqlShow = new FormSQLShow();
            fromSqlShow.sqlStr = showSql.ToString();
            fromSqlShow.Bind();
            fromSqlShow.Show();

        }

        public string GetSqlRow(string type, dynamic dy)
        {
            string rowstr = String.Empty;
            if (type == "BODef")
            {
                var temp = GetTemp(type);
                var temp1 = ConverterToPinYin.GetFirst(dy.colnumName);
                var temp2 = dy.colnumCode;
                var temp3 = dy.colnumName;
                rowstr = string.Format(GetTemp(type), ConverterToPinYin.GetFirst(dy.colnumName), dy.colnumCode, dy.colnumName);
            }

            return rowstr;

        }

        public object GetArrDy(string colnum)
        {

            colnum = colnum.Replace(" ", "");

            var obj = new object();
            if (colnum.Length > 0 && colnum.Contains(":"))
            {
                obj = new
                {
                    colnumCode = colnum.Split(':')[1],
                    colnumName = colnum.Split(':')[0]
                };
            }

            return obj;
        }


        private string GetTemp(string type)
        {

            //        --AM01:内部属性;AM02:只读属性;AM03:受控编辑属性;AM04:任意编辑属性;
            //--AT01:字符串;AT02:数字
            string temp = String.Empty;
            if (type == "BODef")
            {
                temp = "('Project{0}', 'PMS_BT02','','PMS_AG01_SB','AM04','PMS_Project','{1}','{2}','AT01','','',''),\r\n\t";
            }

            return temp;

        }

    }
}
